package com.ytjj.qmyx.mall.controller;


import com.alibaba.fastjson.JSON;
import com.alipay.api.AlipayClient;
import com.alipay.api.DefaultAlipayClient;
import com.alipay.api.domain.TradeComplainQueryResponse;
import com.alipay.api.request.AlipayMerchantTradecomplainBatchqueryRequest;
import com.alipay.api.request.AlipayMerchantTradecomplainQueryRequest;
import com.alipay.api.response.*;
import com.ytjj.common.api.CommonResult;
import com.ytjj.common.controller.BaseController;
import com.ytjj.qmyx.mall.model.AliPayComplatintsFeedbackRequest;
import com.ytjj.qmyx.mall.model.AliPayComplatintsReplyRequest;
import com.ytjj.qmyx.mall.model.AliPayComplatintsSupplementRequest;
import com.ytjj.qmyx.mall.model.WxComplaintsReplyRequest;
import com.ytjj.qmyx.mall.model.request.WxComplaintsCallBackRequest;
import com.ytjj.qmyx.mall.service.AliPayComplaintsService;
import lombok.extern.slf4j.Slf4j;
import net.sf.json.JSONObject;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

/**
 * 支付宝投诉
 * @author
 */
@RestController
@RequestMapping("/aliPayComplaints")
@Slf4j
@RefreshScope
public class AliPayComplaintsController extends BaseController  {
    @Resource
    private AliPayComplaintsService aliPayComplaintsService;


    /**
     * 商户上传反馈图片
     * @param imageUrl
     * @param complaintId
     * @return
     * @throws Exception
     */
    @PostMapping("/uploadAliPayComplaintsImage")
    public CommonResult<String> uploadAliPayComplaintsImage(@RequestParam("imageUrl") String  imageUrl, @RequestParam("complaintId") String complaintId) throws Exception{
        return CommonResult.success(aliPayComplaintsService.uploadAliPayComplaintsImage(imageUrl,complaintId));
    }


    /**
     * 回复用户
     * @param replyRequest
     * @return
     * @throws Exception
     */
    @PostMapping("/complaintsReplySubmit")
    public CommonResult<AlipayMerchantTradecomplainReplySubmitResponse> complaintsReplySubmit(@RequestBody AliPayComplatintsReplyRequest replyRequest) throws Exception{
        AlipayMerchantTradecomplainReplySubmitResponse submitResponse =  aliPayComplaintsService.complaintsReplySubmit(replyRequest);
        return CommonResult.success(submitResponse);
    }


    /**
     * 反馈处理完成
     * @param feedbackRequest
     * @return
     * @throws Exception
     */
    @PostMapping("/complaintsFeedbackSubmit")
    public CommonResult<AlipayMerchantTradecomplainFeedbackSubmitResponse> complaintsFeedbackSubmit(@RequestBody AliPayComplatintsFeedbackRequest feedbackRequest) throws Exception{
        return CommonResult.success(aliPayComplaintsService.complaintsFeedbackSubmit(feedbackRequest));
    }

    /**
     * 投诉查看详情
     * @param complainEventId
     * @return
     * @throws Exception
     */
    @GetMapping("/queryAliPayComplaintsDetail")
    public CommonResult<AlipayMerchantTradecomplainQueryResponse> queryAliPayComplaintsDetail(@RequestParam(value = "complainEventId") String complainEventId,
                                                                                              @RequestParam(value = "childId",required = false) String childId) throws Exception{
        return CommonResult.success(aliPayComplaintsService.queryAliPayComplaintsDetail(complainEventId,childId));
    }

    /**
     * 支付宝投诉回调 废弃
     */
    @RequestMapping("/complaintsCallBack/{childId}")
    public String complaintsCallBack(@RequestBody Map<String, String> params, @PathVariable String childId) throws Exception {
        return  aliPayComplaintsService.complaintsCallBack(params,childId);
    }


    /**
     * 商家补充凭证
     * @param supplementRequest
     * @return
     * @throws Exception
     */
    @PostMapping("/complaintsSupplementSubmit")
    CommonResult<AlipayMerchantTradecomplainSupplementSubmitResponse> complaintsSupplementSubmit(@RequestBody AliPayComplatintsSupplementRequest supplementRequest){
       return CommonResult.success(aliPayComplaintsService.complaintsSupplementSubmit(supplementRequest));
    }

}
